﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EventDemo
{
    public class RecordClass
    {
        public delegate void RecordHandler(object sender, RecordArgs e);//声明委托
        public event RecordHandler Recorded;//声明事件
        public void ShowPage()
        {
            Console.WriteLine("********************************");
            Console.WriteLine("***********添加记录***********");
            Console.WriteLine("-----------------------------------------------------");
            Console.Write("记录编号：");
            int id = int.Parse(Console.ReadLine());
            Console.WriteLine();
            Console.Write("记录描述：");
            string remark = Console.ReadLine();
            Console.WriteLine();
            Console.WriteLine("-----------------------------------------------------");
            Console.WriteLine("1.添加  2.返回 ");
            Console.WriteLine("-----------------------------------------------------");
            string choose = Console.ReadLine();
            if (choose == "1")
            {
                //添加记录操作。。。。事件：添加记录后，记录信息刷新到列表页
                RecordInfo recordInfo = new RecordInfo()
                {
                    Id = id,
                    Remark = remark
                };
                //添加记录实现。。。。省略
                //刷新处理
                OnRecorded(recordInfo);//调用事件---事件触发点
            }
        }
        
        
        //事件触发方法
        private void OnRecorded(RecordInfo record)
        {
            if (Recorded != null)
            {
                RecordArgs e = new RecordArgs(record);
                Recorded(this, e);//执行事件处理程序中的逻辑
            }
        }
    }
}
